<?php

use Biz\cache\samsungActivity\SamsungActivityCache;
use Biz\model\SamsungActivity\SamsungJoinUserListModel;
use Biz\service\SamsungActivity\SamsungJoinUserListService;
use Doraemon\service\User;

class InfoAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    /**
     * @throws \Exception
     */
    public function main()
    {
        $id = trim($this->getRequest()->get('id', ''));
        $data = SamsungJoinUserListModel::getByWhere([
            'id' => $id,
            'status[!]' => SamsungJoinUserListModel::STATUS_DELETE,
        ],
            ['id', 'uid', 'name', 'artist_id', 'avatar', 'nick', 'idea', 'imgs']);
        if ($data) {
            $artWorkUid = $data['uid'] ?? 0;
            if ($artWorkUid > 0) {
                $userinfo = User::getBasicUserInfosByCache([$artWorkUid])[$artWorkUid] ?? [];
                $data['nick'] = $userinfo['nick'] ?? '';
                $data['avatar'] = $userinfo['avatar_small'] ?? '';
            }

            //获取当前用户标识
            $currUid = $this->uid;
            if ($currUid > 0) {
                $uid = $currUid;
            } else {
                $uid = SamsungJoinUserListService::getSecretId();
            }
            $data['secret_id'] = $uid;

            //获取当前用户当日已投票数据
            $userVote = SamsungActivityCache::getTodayUserVote($uid);
            $data['is_vote'] = (int)in_array($id, $userVote);//1：已投票；0：未投票，可继续投票
            $data['is_show_vote'] = SamsungJoinUserListModel::isCanVote();//是否展示投票按钮 1:展示，0:不展示

        } else {
            $data = [];
        }

        $this->setSuccess($data, self::API_CODE_SUCCES);

    }
}